package com.op.studyingliteapp.fragment.pptresource;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.op.studyingliteapp.R;
import com.op.studyingliteapp.fragment.resource.ResourceCellData;

/**
 * @author handsome
 * @version 创建时间：2015年7月26日 下午11:52:17 类说明
 */
public class PPTResourceAdapter extends BaseAdapter {

	private ArrayList<PPTResourceCellData> list;
	private Context mContext;

	public PPTResourceAdapter(Context mContext,
			ArrayList<PPTResourceCellData> ppt_list) {
		this.mContext = mContext;
		this.list = ppt_list;
//		list.add(new PPTResourceCellData("第1章 Java概述",
//				PPTResourceFragment.Location + "java_1.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第2章 Java语言基础",
//				PPTResourceFragment.Location + "java_2.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第3章 类的封装、继承和多态",
//				PPTResourceFragment.Location + "java_3.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第4章 接口、内部类和包",
//				PPTResourceFragment.Location + "java_4.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第5章 异常处理",
//				PPTResourceFragment.Location + "java_5.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第6章 图形用户界面",
//				PPTResourceFragment.Location + "java_6.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("第7章 多线程",
//				PPTResourceFragment.Location + "java_7.pdf",
//				R.drawable.resource_icon));
//		list.add(new PPTResourceCellData("云教学", PPTResourceFragment.Location
//				+ "yunjiaoxue.pdf", R.drawable.resource_icon));
	}


	public Context getContext() {
		return mContext;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public PPTResourceCellData getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		LinearLayout ll = null;
		if (convertView != null) {
			ll = (LinearLayout) convertView;
		} else {
			ll = (LinearLayout) LayoutInflater.from(getContext()).inflate(
					R.layout.item_ppt, null);
		}
		final PPTResourceCellData data = getItem(position);

		ImageView ppt_img = (ImageView) ll.findViewById(R.id.ppt_image);
		TextView ppt_name = (TextView) ll.findViewById(R.id.ppt_name);

		ppt_img.setImageResource(data.getIconId());
		ppt_name.setText(data.getName());
		return ll;
	}
}
